package cn.tedu.rabbitmqspringboot.m4;

import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;


@SpringBootApplication
public class Main {

    @Autowired
    private Producer p;

    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }

    @Bean
    public DirectExchange logsExchange(){
                                        //名字,非持久,自动删除
        return new DirectExchange("direct_logs",false,false);//默认是持久的
    }

    //spring扫描创建完所有的实例,完成所有的依赖注入后,
    //自动执行 PostConstruct 注解的方法
    @PostConstruct
    public void test(){
//        new Thread(new Runnable(){
//            @Override
//            public void run() {
//                p.send();
//            }
//        }).start();

        //lambda表达式 == Runnable匿名内部类
        new Thread(() -> p.send()).start();

    }
}
